package com.ct.goods.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ct.goods.orm.GoodsSeckill;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 秒杀商品表 Mapper 接口
 * </p>
 *
 * @author system
 */
public interface GoodsSeckillMapper extends BaseMapper<GoodsSeckill> {

    @Select("SELECT * FROM goods_seckill WHERE goods_id = #{goodsId} LIMIT 1")
    @Options(useCache = false)
    GoodsSeckill getByGoodsId(Long goodsId);


    @Update("UPDATE goods_seckill SET version=version+1,stock=stock-1,sold_number=sold_number+1 " +
            "WHERE id=#{id}  and version=#{version}")
    boolean decreStock(Long id,int version);
}
